package com.diyunapp.xilinapp.utils;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonUtils {
	public static List<City> getListFromJson(byte[] b) {
		List<City> list_city;
		try {
			list_city = new ArrayList<City>();
			JSONObject response = new JSONObject(new String(b, "utf-8"));
			JSONArray data = response.getJSONArray("date");
			//
			for (int i = 0; i < data.length(); i++) {
				// Toast.makeText(getApplicationContext(),"dd2",Toast.LENGTH_SHORT).show();

				City city = new City();
				JSONObject jsono = data.getJSONObject(i);
				String area_id = jsono.getString("area_id");
				String area_name = jsono.getString("area_name");
				city.setArea_id(area_id);
				city.setArea_name(area_name);
				list_city.add(city);
			}
			return list_city;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}
}